<?php

namespace App\Admin\Controllers;

use App\Models\MerchantApply;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class MerchantApplyController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '进件申请';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new MerchantApply());
        
        $grid->column('id_card_no', __('Id card no'));
        $grid->column('id_card_name', '身份证号');
        $grid->column('contact_mobile', __('Contact mobile'));
        $grid->column('contact_email', __('Contact email'));
        $grid->column('bank_no', '银行卡号');
        $grid->column('acct_mobile', __('Acct mobile'));
        $grid->column('id_card_front', __('Id card front'))->image('', '50');
        $grid->column('id_card_back', __('Id card back'))->image('', '50');
        $grid->column('bank_card_front', __('Bank card front'))->image('', '50');
        $grid->column('status', __('Status'))->using([1 => '申请中', 2 => '申请完成'])->dot([1 => 'danger', 2 =>'success']);
        $grid->column('created_at', __('Created at'));
        
        $grid->filter(function (Grid\Filter $filter) {
        	$filter->disableIdFilter();
        	$filter->like('id_card_name');
        	$filter->like('contact_mobile');
        	$filter->like('contact_email');
        });

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(MerchantApply::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('id_card_no', __('Id card no'));
        $show->field('id_card_name', __('Id card name'));
        $show->field('contact_mobile', __('Contact mobile'));
        $show->field('contact_email', __('Contact email'));
        $show->field('bank_no', __('Bank no'));
        $show->field('acct_mobile', __('Acct mobile'));
        $show->field('id_card_front', __('Id card front'));
        $show->field('id_card_back', __('Id card back'));
        $show->field('bank_card_front', __('Bank card front'));
        $show->field('status', __('Status'));
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));
        $show->field('deleted_at', __('Deleted at'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new MerchantApply());

        $form->text('id_card_no', __('Id card no'));
        $form->text('id_card_name', __('Id card name'));
        $form->text('contact_mobile', __('Contact mobile'));
        $form->text('contact_email', __('Contact email'));
        $form->text('bank_no', __('Bank no'));
        $form->text('acct_mobile', __('Acct mobile'));
        $form->image('id_card_front', __('Id card front'));
        $form->image('id_card_back', __('Id card back'));
        $form->image('bank_card_front', __('Bank card front'));
        $form->radioButton('status', __('Status'))->options([1 => '申请中', 2 => '申请完成']);

        return $form;
    }
}
